package block

//切片
//用来管理区块的
type BlockChain struct {
	Blocks []*Block
}

/**
创建区块链
*/
func CreateChain(data []byte) *BlockChain {
	//初始化一个区块链
	bc := BlockChain{}
	//实例化
	bc.Blocks = []*Block{}
	//创建一个带有创世区块的区块链
	genesis := GenesisBlock(data)
	bc.Blocks = append(bc.Blocks, genesis)
	return &bc
}

/**
添加新区块到区块链中
*/
func (bc *BlockChain) AddBlock(data []byte) {
	//1.创建区块
	newBlock := CreateBlock(data, bc.Blocks[len(bc.Blocks)-1].Hash)
	//2.添加到区块链中
	bc.Blocks = append(bc.Blocks, newBlock)
}
